package 线程安全.多线程;

import java.io.*;
import java.net.Socket;

public class FileUpload_Client {
    public static void main(String[] args) throws Exception {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("")));
        Socket socket = new Socket("127.0.0.1", 6666);
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());


        byte[] bytes = new byte[1024 * 8];
        int len = 0;
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes, 0, len);
        }
        bos.flush();
        socket.shutdownOutput();
        System.out.println("file send finsih!");

        InputStream inputStream = socket.getInputStream();
        byte[] back = new byte[1024 * 8];
        while ((len = inputStream.read(back)) != -1) {
            System.out.println(new String(back, 0, len));
        }

        inputStream.close();
        socket.close();
        bis.close();
    }
}
